libxenlight: correct broken osdeps.[ch] and make #includes consistent
authorKeir Fraser <keir.fraser@citrix.com>
Mon, 23 Nov 2009 07:00:08 +0000 (07:00 +0000)
committerKeir Fraser <keir.fraser@citrix.com>
Mon, 23 Nov 2009 07:00:08 +0000 (07:00 +0000)
osdeps.[hc] previously mistakenly declared and defined [v]asprintf.
These functions are available in the libc on most platforms.  Also,
osdeps.h is used by xc.c but xc.c is not part of the library, so
osdeps.h is part of the public interface and should have a better
name.

So now, instead:

 * osdeps.h is libxl_osdeps.h.

 * _GNU_SOURCE is #defined in libxl_osdeps.h so that we get the system
   [v]asprintf (and various other functions)

 * libxl_osdeps.h is included first in every libxl*.c file (it needs
   to be before any system headers so that _GNU_SOURCE) takes effect.

 * osdeps.[hc] only provide their own reimplementation of [v]asprintf
   if NEED_OWN_ASPRINTF is defined.  Currently it is not ever defined
   but this is provided for any platform which needs it.

 * While I was editing the #includes in each .c file, I put them all
   into the same order: "libxl_osdeps.h", then system headers,
   then local headers.

 * xs.h is included in libxl.h.  This is needed for "bool"; it has to
   not be typedefed in libxl.h because otherwise we get a duplicate
   definition when including xs.h.

Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
13 files changed:
tools/libxl/Makefile
tools/libxl/libxl.c
tools/libxl/libxl.h
tools/libxl/libxl_device.c
tools/libxl/libxl_dom.c
tools/libxl/libxl_exec.c
tools/libxl/libxl_internal.c
tools/libxl/libxl_osdeps.h [new file with mode: 0644]
tools/libxl/libxl_utils.c
tools/libxl/libxl_xshelp.c
tools/libxl/osdeps.c
tools/libxl/osdeps.h [deleted file]
tools/libxl/xl.c

index 492d6d9151f7303d9f6ca0726c252b4e458d4d2c..0358cea7b53e138f18e10a94cc9e48bbb19946e7 100644 (file)
@@ -23,8 +23,7 @@ LIBCONFIG_URL ?= http://www.hyperrealm.com/libconfig
 LIBCONFIG_SOURCE = libconfig-1.3.2
 LIBCONFIG_OUTPUT = $(LIBCONFIG_SOURCE)/.libs
 
-LIBXL_OBJS-y =
-LIBXL_OBJS-$(CONFIG_Linux) += osdeps.o
+LIBXL_OBJS-y = osdeps.o
 LIBXL_OBJS = flexarray.o libxl.o libxl_dom.o libxl_exec.o libxl_xshelp.o libxl_device.o libxl_internal.o xenguest.o libxl_utils.o $(LIBXL_OBJS-y)
 
 CLIENTS = xl
index 2eea3a813872b2fed308c7c563b9fb65b611da03..c20025ff90c61a203fda1f60118f75b2c0dfbaf9 100644 (file)
@@ -14,6 +14,8 @@
  * GNU Lesser General Public License for more details.
  */
 
+#include "libxl_osdeps.h"
+
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
@@ -25,6 +27,7 @@
 #include <unistd.h> /* for write, unlink and close */
 #include <stdint.h>
 #include <inttypes.h>
+
 #include "libxl.h"
 #include "libxl_utils.h"
 #include "libxl_internal.h"
index 0c6f168feebf025a4424e59626c06998463d0e89..ac4c79e39c8e6c9b09b578792889f4bef6ee21f5 100644 (file)
 #ifndef LIBXL_H
 #define LIBXL_H
 
-#include "osdeps.h"
 #include <stdint.h>
 #include <stdarg.h>
 #include <netinet/in.h>
 #include <xenctrl.h>
-#include "xen_uuid.h"
+#include <xs.h>
 
-typedef int bool;
+#include "xen_uuid.h"
 
 typedef void (*libxl_log_callback)(void *userdata, int loglevel, const char *file,
                                    int line, const char *func, char *s);
index 82a2a305809d8275f934abff7e881ca42ea5a45a..451233fd4fabc1e00a28ce9441497fea745f74d0 100644 (file)
  * GNU Lesser General Public License for more details.
  */
 
+#include "libxl_osdeps.h"
+
 #include <string.h>
 #include <stdio.h>
-#include "libxl.h"
-#include "libxl_internal.h"
 #include <sys/time.h> /* for struct timeval */
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <unistd.h>
 
+#include "libxl.h"
+#include "libxl_internal.h"
+
 char *string_of_kinds[] = {
     [DEVICE_VIF] = "vif",
     [DEVICE_VBD] = "vbd",
index e3cf4374c5a901a83174c6357becb339d5a23be0..68b2b21378e0bf8656c997ba850ee1a676c07027 100644 (file)
  * GNU Lesser General Public License for more details.
  */
 
-#include "libxl.h"
-#include "libxl_internal.h"
+#include "libxl_osdeps.h"
+
 #include <stdio.h>
 #include <inttypes.h>
-#include <xenguest.h>
-#include <xenctrl.h>
-#include <xc_dom.h>
 #include <string.h>
 #include <sys/time.h> /* for struct timeval */
 #include <unistd.h> /* for sleep(2) */
 
+#include <xenctrl.h>
+#include <xc_dom.h>
+#include <xenguest.h>
+
+#include "libxl.h"
+#include "libxl_internal.h"
+
 int is_hvm(struct libxl_ctx *ctx, uint32_t domid)
 {
     xc_domaininfo_t info;
@@ -110,7 +114,7 @@ int build_pv(struct libxl_ctx *ctx, uint32_t domid,
 
     dom = xc_dom_allocate(info->u.pv.cmdline, info->u.pv.features);
     if (!dom) {
-        XL_LOG_ERRNOVAL(ctx, XL_LOG_ERROR, dom, "xc_dom_allocate failed");
+        XL_LOG_ERRNO(ctx, XL_LOG_ERROR, "xc_dom_allocate failed");
         return -1;
     }
     if ((ret = xc_dom_linux_build(ctx->xch, dom, domid, info->max_memkb / 1024,
index 8a589b676c7b23306037f923b13ed31d498b5f14..5186ac8c7c105fc3ae5108635e2becdffd7c965b 100644 (file)
  * GNU Lesser General Public License for more details.
  */
 
+#include "libxl_osdeps.h"
+
 #include <stdio.h>
 #include <unistd.h>
 #include <stdlib.h>
+
 #include "libxl.h"
 #include "libxl_internal.h"
 
index 7ba0c9790f2df8bc07f2fdf8b72fa369dc44e039..a04ac8ddf7decdf6598eaafd1c84fb351a4499df 100644 (file)
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU Lesser General Public License for more details.
  */
-#include "libxl.h"
-#include "libxl_internal.h"
-#include "libxl_utils.h"
+
+#include "libxl_osdeps.h"
+
 #include <stdio.h>
 #include <stdarg.h>
 #include <string.h>
 
+#include "libxl.h"
+#include "libxl_internal.h"
+#include "libxl_utils.h"
+
 int libxl_error_set(struct libxl_ctx *ctx, int code)
 {
     return 0;
diff --git a/tools/libxl/libxl_osdeps.h b/tools/libxl/libxl_osdeps.h
new file mode 100644 (file)
index 0000000..fc453c3
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2009      Citrix Ltd.
+ * Author Stefano Stabellini <stefano.stabellini@eu.citrix.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; version 2.1 only. with the special
+ * exception on linking described in file LICENSE.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ */
+
+/*
+ * This header must be included first, before any system headers,
+ * so that _GNU_SOURCE takes effect properly.
+ */
+
+#ifndef LIBXL_OSDEP
+#define LIBXL_OSDEP
+
+#define _GNU_SOURCE
+
+#ifdef NEED_OWN_ASPRINTF
+#include <stdarg.h>
+
+int asprintf(char **buffer, char *fmt, ...);
+int vasprintf(char **buffer, const char *fmt, va_list ap);
+#endif /*NEED_OWN_ASPRINTF*/
+
+#endif
index 5048fd06aaf91c796309216dd74935971a007c2a..c174d0f5107339c7cf8bcae90f4998aaf3a5139b 100644 (file)
@@ -13,8 +13,8 @@
  * GNU Lesser General Public License for more details.
  */
 
-#include "libxl_utils.h"
-#include "libxl_internal.h"
+#include "libxl_osdeps.h"
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdint.h>
@@ -24,6 +24,8 @@
 #include <ctype.h>
 #include <errno.h>
 
+#include "libxl_utils.h"
+#include "libxl_internal.h"
 
 
 unsigned long libxl_get_required_shadow_memory(unsigned long maxmem_kb, unsigned int smp_cpus)
index f59eee75238d39836bae0ade851ef6bb4ba90e7c..87c494a4a516610e2e79c3af91ab852821d843d4 100644 (file)
  * GNU Lesser General Public License for more details.
  */
 
+#include "libxl_osdeps.h"
+
 #include <string.h>
 #include <stddef.h>
-#include "libxl.h"
-#include "libxl_internal.h"
 #include <stdio.h>
 #include <stdarg.h>
 
+#include "libxl.h"
+#include "libxl_internal.h"
+
 char **libxl_xs_kvs_of_flexarray(struct libxl_ctx *ctx, flexarray_t *array, int length)
 {
     char **kvs;
index 81175aa328d8da736485b53c5d5b26f947fc90f7..ad96480a85a19e4d995a55d928a58536298f19bf 100644 (file)
@@ -19,6 +19,8 @@
 #include <sys/time.h>
 #include <stdlib.h>
 
+#ifdef NEED_OWN_ASPRINTF
+
 int vasprintf(char **buffer, const char *fmt, va_list ap)
 {
     int size = 0;
@@ -60,3 +62,5 @@ int asprintf(char **buffer, char *fmt, ...)
     va_end (ap);
     return status;
 }
+
+#endif
diff --git a/tools/libxl/osdeps.h b/tools/libxl/osdeps.h
deleted file mode 100644 (file)
index 5391727..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Copyright (C) 2009      Citrix Ltd.
- * Author Stefano Stabellini <stefano.stabellini@eu.citrix.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published
- * by the Free Software Foundation; version 2.1 only. with the special
- * exception on linking described in file LICENSE.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU Lesser General Public License for more details.
- */
-
-#ifndef LIBXL_OSDEP
-#define LIBXL_OSDEP
-
-#include <stdarg.h>
-
-#if defined(__linux__)
-int asprintf(char **buffer, char *fmt, ...);
-int vasprintf(char **buffer, const char *fmt, va_list ap);
-#endif
-
-#endif
index 3b735ec78a588a9ee41e61266970a52a6ca28e11..727fe4a83747839f8fdffb3080cfb9a164817eb7 100644 (file)
@@ -14,8 +14,8 @@
  * GNU Lesser General Public License for more details.
  */
 
-#include "libxl.h"
-#include "libxl_utils.h"
+#include "libxl_osdeps.h"
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -29,6 +29,9 @@
 #include <arpa/inet.h>
 #include <xenctrl.h>
 
+#include "libxl.h"
+#include "libxl_utils.h"
+
 void log_callback(void *userdata, int loglevel, const char *file, int line, const char *func, char *s)
 {
     fprintf(stderr, "[%d] %s:%d:%s: %s\n", loglevel, file, line, func, s);